
from WtfEngine import *;
from Util import *;
import Multipliers;
import Traits;
import Technology;
import Trade;
import Commodities;

class Society(GameObject):
	def __init__(self):
		
		self.names = DictToObject({
			'name': "Senau",
			'noun': "Senaui",
			'adj': "Senauan",
			'leader': "Senaus",
			'title': "Supreme Commander"
		});
		
		self.cities = [];
		self.technologies = [];
		self.traits = {
			'govt': Traits.gTraits.govt.values.tribal,
			'econ': Traits.gTraits.econ.values.barter,
			'labour': Traits.gTraits.labour.values.tribal
		}
		
		#self.multipliers = self.CalculateMultipliers();

		self.market = Trade.Market(self);
		
		# Test traders
		t = Trade.Trader();
		t.AddCommodity(Commodities.Coal(0));
		t.AddCommodity(Commodities.Bonds(5));
		t.AddCommodity(Commodities.Food(0));
		t.AddCommodity(Commodities.Spices(5));
		t.SetDemand("Coal", 5);
		t.SetDemand("Food", -3);
		self.market.traders.append(t);
		
		t = Trade.Trader();
		t.AddCommodity(Commodities.Coal(0));
		t.AddCommodity(Commodities.Food(0));
		t.SetDemand("Food", 5);
		t.SetDemand("Coal", -5);
		self.market.traders.append(t);
	
	
	def GetGovtReserves(self):
		cs = {};
		for k in self.commodities:
			cs[k] = self.commodities[k].commodity;
		return cs;
	
	def GrantTechnology(self, tech):
		self.technologies.append(tech);
		
	def HasTechnology(self, techType):
		for tech in self.technologies:
			if isinstance(tech, techType):
				return True;
		return False;
	
	def CalculateMultipliers(self, ms = Multipliers.Multipliers()):
		for t in self.technologies:
			ms = t.CalculateMultipliers(ms);
		for t in self.traits.itervalues():
			ms = t.CalculateMultipliers(ms);

	def DoTrading(self):
		if not "marketData" in self.market.__dict__:
			self.market.CalculateMarketData();
		self.market.SetPrices();
		self.market.DoTrading();
		self.market.Process();
		self.market.SetPrices();
		
	
	def GetSalesTaxRate(self, trader, n):
		return 0;
	
	def GetCentralMarket(self):
		return self.market;

